package com.cskaoyan.gateway.controller.shopping;
/*
 * @author 魏骏杰
 */

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/shopping")
@Anoymous
public class HomepageController {

    @Reference(timeout = 3000, retries = 2, check = false)
    IHomeService iHomeService;

    @Reference
    IContentService iContentService;

    @Reference
    IProductCateService iProductCateService;


    @GetMapping("/homepage")
    @Anoymous
    public ResponseData homepageList() {
        HomePageResponse response = iHomeService.homepage();
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @GetMapping("/navigation")
    @Anoymous
    public ResponseData navigation() {
        NavListResponse response = iContentService.queryNavList();
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @GetMapping("/categories")
    @Anoymous
    public ResponseData categories(AllProductCateRequest request) {
        AllProductCateResponse response = iProductCateService.getAllProductCate(request);
        if (response.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
